//----------------------------------------------------------------------
//	Copyright (C) 2011 Matias N. Goldberg ("dark_sylinc")
//
//  This is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this.  If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------

#ifndef __AnimPosePanel__
#define __AnimPosePanel__

/**
@file
Subclass of wxAnimPosePanel, which is generated by wxFormBuilder.
*/

#include "../wxOgreMeshViewerMainFrame.h"

#include <OgrePrerequisites.h>

//// end generated include

/** Implementing wxAnimPosePanel */
class AnimPosePanel : public wxAnimPosePanel
{
	struct PoseCtrls
	{
		wxTextCtrl	*weightText;
		wxSlider	*weightSlider;
	};

	enum
	{
		wxID_POSESLIDERSTART	= 20000,
		wxID_POSETEXTSTART		= 25000
	};

	Ogre::Entity			*m_loadedEntity;
	Ogre::SceneManager		*m_sceneManager;

	Ogre::AnimationState	*m_currentAnimationState;
	Ogre::Animation			*m_currentAnimation;
	bool					m_playAnimation; //True if our parent should play our current animation
	float					m_animationRate;
	bool					m_manualMode;

	std::vector<PoseCtrls>	m_poseCtrls;

	void createKeyScrolls();
	void removeKeyScrolls();

	void updateKeyScrolls();
	void setManualMode( bool bManualMode );

	void updatePose( int poseIdx, float newWeight );
	void copyPoseFromTextCtrls();

protected:
	// Handlers for wxAnimPosePanel events.
	void OnChangedAnimationName( wxCommandEvent& event );
	void OnAnimationChangeTime( wxCommandEvent& event );
	void OnAnimationChangeTimeSlider( wxScrollEvent& event );
	void OnButtonPlaybackAnim( wxCommandEvent& event );
	void OnAnimationRateChange( wxCommandEvent& event );
	void OnLoopAnimation( wxCommandEvent& event );
	void OnPoseWeightBox( wxCommandEvent& event );
	void OnPoseWeightSlider( wxScrollEvent& event );
	void OnResetWeights( wxCommandEvent& event );

	public:
	/** Constructor */
	AnimPosePanel( wxWindow* parent, Ogre::SceneManager *sceneManager );
	//// end generated class members

	void meshLoaded( Ogre::Entity *meshEntity );
	void meshUnload();

	bool getPlayAnimation() const { return m_playAnimation; }
	float getAnimationRate() const { return m_animationRate; }
	Ogre::AnimationState* getCurrentAnimationState() const { return m_currentAnimationState; }

	bool isManualMode() const { return m_manualMode; }

	void timeUpdated();
	void manualModeUpdate()					{ copyPoseFromTextCtrls(); }
};

#endif // __AnimPosePanel__
